package com.cal.conut;

import com.cal.conut.*;
import android.app.Activity;
import android.os.Bundle;
import android.view.Display;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnKeyListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class CalculatorActivity extends Activity {
    /** Called when the activity is first created. */
	
	int firstnum;
	int secondnum;
    EditText display;
    
    private EditText txtCalc;
    private Button buttonZero;
    private Button buttonOne;
    private Button buttonTwo;
    private Button buttonThree;
    private Button buttonFour;
    private Button buttonFive;
    private Button buttonSix;
    private Button buttonSeven;
    private Button buttonEight;
    private Button buttonNine;
    private Button buttonPlus;
    private Button buttonMinus;
    private Button buttonMultiply;
    private Button buttonDivide;
    private Button buttonEquals;
    private Button buttonClear;
    private TextView opretaor ; 
    private boolean hasChanged = false;
    
    
    private void handleNumber(Integer i) {
		// TODO Auto-generated method stub
		
		EditText cal = (EditText) findViewById(R.id.txtCalc);
    	cal.setText(cal.getText()+i.toString());
	}
    
    
  	  
    
	
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        firstnum = 0;
        secondnum = 0;
         buttonEquals = (Button) findViewById(R.id.buttonEquals);
          buttonPlus = (Button) findViewById(R.id.buttonPlus);
          buttonMinus = (Button) findViewById(R.id.buttonMinus);
          buttonMultiply = (Button) findViewById(R.id.buttonMultiply);
          buttonDivide = (Button) findViewById(R.id.buttonDivide);
          buttonOne = (Button) findViewById(R.id.buttonOne);
          buttonTwo = (Button) findViewById(R.id.buttonTwo);
          buttonThree = (Button) findViewById(R.id.buttonThree);
          buttonFour = (Button) findViewById(R.id.buttonFour);
          buttonFive = (Button) findViewById(R.id.buttonFive);
          buttonSix = (Button) findViewById(R.id.buttonSix);
          buttonSeven = (Button) findViewById(R.id.buttonSeven);
          buttonEight = (Button) findViewById(R.id.buttonEight);
          buttonNine = (Button) findViewById(R.id.buttonNine);
          buttonZero = (Button) findViewById(R.id.buttonZero);                  
         EditText txtCalc = (EditText) findViewById(R.id.txtCalc);
         
         buttonEquals.setOnClickListener(new Button.OnClickListener(){
        	 public void onClick(View v){
        		 
        		 opretaor.setText("=");
        	 }
         });
         
         buttonPlus.setOnClickListener(new Button.OnClickListener(){
        	 public void onClick(View v){
        		 opretaor.setText("+");
        		 
        	 }
         });
         
         buttonMinus.setOnClickListener(new Button.OnClickListener(){
        	 public void onClick(View v){
        		 opretaor.setText("-");
        	 }
         });
         
         buttonMultiply.setOnClickListener(new Button.OnClickListener(){
        	 public void onClick(View v){
        		 opretaor.setText("*");
        	 }
         });
         
         buttonDivide.setOnClickListener(new Button.OnClickListener(){
        	 public void onClick(View v){
        		 opretaor.setText("+");
        	 }
         });
         
         buttonOne.setOnClickListener(new Button.OnClickListener(){
        	 public void onClick(View v){
        		 handleNumber(1);
        	 }

			

         });
         
         buttonTwo.setOnClickListener(new Button.OnClickListener(){
        	 public void onClick(View v){
        		 handleNumber(2);
        	 }
         });
         
         buttonThree.setOnClickListener(new Button.OnClickListener(){
        	 public void onClick(View v){
        		 handleNumber(3);
        	 }
         });
         
         buttonFour.setOnClickListener(new Button.OnClickListener(){
        	 public void onClick(View v){
        		 handleNumber(4);
        	 }
         });
         
         buttonFive.setOnClickListener(new Button.OnClickListener(){
        	 public void onClick(View v){
        		 handleNumber(5);
        	 }
         });
         
         buttonSix.setOnClickListener(new Button.OnClickListener(){
        	 public void onClick(View v){
        		 handleNumber(6);
        	 }
         });
         
         buttonSeven.setOnClickListener(new Button.OnClickListener(){
        	 public void onClick(View v){
        		 handleNumber(7);
        	 }
         });
         
         buttonEight.setOnClickListener(new Button.OnClickListener(){
        	 public void onClick(View v){
        		 handleNumber(8);
        	 }
         });
         
         buttonNine.setOnClickListener(new Button.OnClickListener(){
        	 public void onClick(View v){
        		 handleNumber(9);
        	 }
         });
         
         buttonZero.setOnClickListener(new Button.OnClickListener(){
        	 public void onClick(View v){
        		 handleNumber(0); 
        		 
        	 }
         });
         
         txtCalc.setOnKeyListener(new OnKeyListener() {
        	   public boolean onKey(View v, int i, android.view.KeyEvent e) {
        	    if (e.getAction() == KeyEvent.ACTION_DOWN) {
        	     int keyCode = e.getKeyCode();

        	     // txtCalc.append("["+Integer.toString(keyCode)+"]");

         
         switch (keyCode) {
         case KeyEvent.KEYCODE_0:
          handleNumber(0);
          break;

         case KeyEvent.KEYCODE_1:
          handleNumber(1);
          break;

         case KeyEvent.KEYCODE_2:
          handleNumber(2);
          break;

         case KeyEvent.KEYCODE_3:
          handleNumber(3);
          break;

         case KeyEvent.KEYCODE_4:
          handleNumber(4);
          break;

         case KeyEvent.KEYCODE_5:
          handleNumber(5);
          break;

         case KeyEvent.KEYCODE_6:
          handleNumber(6);
          break;

         case KeyEvent.KEYCODE_7:
          handleNumber(7);
          break;

         case KeyEvent.KEYCODE_8:
          handleNumber(8);
          break;

         case KeyEvent.KEYCODE_9:
          handleNumber(9);
          break;

       
         
        
    
        
         }
        	    }

        	    return true;
        	   }
        	  });
        	 }
    
   
    
    
    
    	  
    }	  
    
    
   

        
				
				
			
        
			  
 
